<div class="layui-fluid layui-anim febs-anim" id="febs-evaluation" lay-title="价值评估">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="dictDetail-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">油站名称</label>
                                        <div class="layui-input-inline">
                                            <select id="siteSelect" lay-filter="siteFilter" name="shellSite" lay-verify="required" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="shellStatement:add">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="evaluationTable" lay-data="{id: 'evaluationTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="evaluation-option">
    <span shiro:lacksPermission="shellStatement:add,shellStatement:update,shellStatement:info,shellStatement:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <span shiro:hasPermission="shellStatement:update"><button lay-event="update" type="button" class="layui-btn layui-btn-xs">修改</button></span>
    <span shiro:hasPermission="shellStatement:delete"><button lay-event="delete" type="button" class="layui-btn layui-btn-xs">删除</button></span>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-evaluation'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            tableIns,
            siteId = "",//判断是否进行油站选择
            element = layui.element;

        form.render();

        initTable();
        initDataSite();

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('evaluationTable');
                if (name === 'add') {
                    febs.view.tab.change("/activity/shellStatement/add/" + 0);
                }
                //los angle
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的价值评估表');
                    } else {
                        febs.modal.confirm('删除价值评估', '确定删除价值评估表？', function () {
                            var Ids = [];
                            layui.each(checkStatus.data, function (key, item) {
                                Ids.push(item.id)
                            });
                            deleteOilPrice(Ids.join(','));
                        });
                    }
                }
            },
            options: [{
                name: 'add',
                title: '新增价格评估',
                perms: 'shellStatement:add'
            }, {
                name: 'delete',
                title: '删除价格评估',
                perms: 'shellStatement:delete'
            }]
        });

        table.on('tool(evaluationTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'update') {
                var str = JSON.stringify(data);
                localStorage.setItem("evaluationObj", str);
                febs.view.tab.change("/activity/shellStatement/add/" + 1);
            }
            if (layEvent === 'delete') {
                febs.modal.confirm('删除价值评估', '确定删除该删除价值评估表？', function () {
                    deleteOilPrice(data.id);
                });
            }
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });
        form.on('select(siteFilter)', function (data) {
            $('#febs-evaluation').find('#query').click();
        });

        //列表数据-请求
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'evaluationTable',
                url: ctx + 'shellStatement/shellStatementList',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'shellName', title: '评估油站名称', minWidth: 100},
                    {field: 'siteAddress', title: '油站地址', minWidth: 100},
                    {field: 'evaluator', title: '评估人', minWidth: 100},
                    {field: 'optDate', title: '时间', minWidth: 100},
                    {title: '操作', toolbar: '#evaluation-option', minWidth: 140}
                ]]
            });
        }
        function getQueryParams() {
            return {
                shellId: $searchForm.find("select[name='shellSite']").val(),
                name: $searchForm.find('input[name="name"]').val()
            };
        }
        //搜索-油站-请求
        function initDataSite() {
            febs.get(ctx + 'shellActivity/shellOilList', null, function (res) {
                if (res.code === 200) {
                    res.data.map(function (item,index) {
                        $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                    });
                    form.render("select");
                    return false;
                }
            })
        }

        function deleteOilPrice(dsIds) {
            febs.get(ctx + 'shellStatement/shellStatement/' + dsIds , null, function () {
                febs.alert.success('删除成功');
                $query.click();
            });
        }

    })
</script>